#[derive(Debug)]

// 定义结构体
pub struct Student {
    pub name: String,
    pub age: u32,
}

// 定义 trait
trait GetName {
    fn get_name(&self) -> &String;
}

trait GetAge {
    fn get_age(&self) -> u32;
}

// 实现 trait
impl GetName for Student {
    fn get_name(&self) -> &String {
        return &self.name;
    }
}

impl GetAge for Student {
    fn get_age(&self) -> u32 {
        return *&self.age;
    }
}

fn produce_item_with_age() -> impl GetAge {
    Student {
        name: String::from("小明"),
        age: 10,
    }
}

// 写法1
fn print_info1<T: GetName + GetAge>(item: &T) {
    println!("naem={}", item.get_name());
    println!("age={}", item.get_age());
}

// 写法2
fn print_info2<T>(item: &T) where T: GetName + GetAge {
    println!("naem={}", item.get_name());
    println!("age={}", item.get_age());
}

fn main() {
    let mut student1 = Student {
        name: "小明".to_string(),
        age: 10,
    };
    println!("写法1：");
    print_info1(&student1);
    println!("写法2：");
    print_info2(&student1);

    let s = produce_item_with_age();
    // println!("{:#?}", s.name);
}
